<?php

/**
 * My Application bootstrap file.
 */
use Nette\Application\Routers\Route;
use CMS\Core;


// Load Nette Framework
require LIBS_DIR . '/Nette/loader.php';
require_once LIBS_DIR . '/Doctrine/Common/ClassLoader.php';


$classloader = new Doctrine\Common\ClassLoader('Doctrine', realpath(LIBS_DIR));
$classloader->register();

// Configure application
$configurator = new Nette\Config\Configurator;

// Enable Nette Debugger for error visualisation & logging
//$configurator->setProductionMode($configurator::AUTO);
$configurator->enableDebugger(__DIR__ . '/../log');

// Enable RobotLoader - this will load all classes automatically
$configurator->setTempDirectory(__DIR__ . '/../temp');
$configurator->createRobotLoader()
	->addDirectory(APP_DIR)
	->addDirectory(LIBS_DIR . '/CMS')
	->addDirectory(LIBS_DIR . '/Gridito')
	->addDirectory(LIBS_DIR . '/Nella')
	->addDirectory(LIBS_DIR . '/Symfony')
	->register();

\Nella\Addons\Doctrine\Config\Extension::register($configurator);
\Nella\Addons\Doctrine\Config\MigrationsExtension::register($configurator);
	
// Create Dependency Injection container from config.neon file
$configurator->addConfig(__DIR__ . '/config/config.neon');
$container = $configurator->createContainer();

Route::$styles['#raw'] = array(
    Route::FILTER_OUT => null,
    Route::PATTERN => "^(?!admin\/).*?",
);

$container->router[] = new Route('[<url #raw>]', array(
        'module' => 'Page',
        'presenter' => 'PageFront',
        'action' => 'default',));

$container->router[] = new Route('admin/<module>/<presenter>/<action>/<id>', array(
        'module' => 'User',
        'presenter' => 'Login',
        'action' => 'default',
        'id' => NULL));

$database = $container->getService("database");
$core = Core::getInstance();
$core->setEm($database);
$core->loadModules();

// Configure and run the application!
if (PHP_SAPI == 'cli') {
	$container->console->run();
} else {
	$container->application->run();
}
